package com.zshield.entry;

import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import com.zshield.util.Etime;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public class ContentAnalysisEntry implements EntryInterface<ContentAnalysisEntry> {
    @SerializedName("@timestamp")
    private String timeStamp;
    @SerializedName("SENSOR_ID")
    private String sensorId;
    @SerializedName("TIME")
    private String time;
    @SerializedName("FORMAT")
    private String format;
    @SerializedName("DAY_TIME")
    private String dayTime;
    @SerializedName("FILE_NAME")
    private String fileName;
    @SerializedName("FILE_PATH")
    private String filePath;
    @SerializedName("UUID")
    private String uuid;
    @SerializedName("KEYWORD")
    private String keyWord;
    @SerializedName("PTYPE")
    private String ptype;
    @SerializedName("VIOLATION_TIMES")
    private int violationTimes;
    @SerializedName("MATCH_FILE_NAME")
    private String matchFileName;

    public ContentAnalysisEntry(JsonObject obj) {
        sensorId = obj.get("SENSOR_ID").getAsString();
        filePath = obj.get("FILE_PATH").getAsString();
        fileName = obj.get("FILE_NAME").getAsString();
        uuid = obj.get("UUID").getAsString();
        keyWord = obj.get("KEYWORD").getAsString();
        String logTime = obj.get("TIME").getAsString();
        Etime etime = new Etime();
        time = etime.zoneParse(logTime);
        matchFileName = obj.get("MATCH_FILE_NAME").getAsString();
        LocalDate ldt = LocalDate.parse(time, Etime.DATETIME_FORMATTER);
        dayTime = ldt.format(Etime.DATE_FORMATTER);
        timeStamp = LocalDateTime.now().format(Etime.DATETIME_FORMATTER);
        format = "PRE_COMPUTE";
        ptype = "FileParse";
        violationTimes = 1;
    }

    @Override
    public void update(ContentAnalysisEntry that) {
        this.time = that.time;
        this.violationTimes = this.violationTimes + that.violationTimes;
    }

    @Override
    public String getDayTime() {
        return this.dayTime;
    }

    @Override
    public String getDocId() {
        return  "ContentAnalysis~"+ sensorId + "~" + uuid + "~" + matchFileName + "~" + keyWord + "~" + filePath + "~" + dayTime;
    }
}
